﻿package com.zouloux.graphics.menu.views 
{
	import com.zouloux.core.IExecutable;
	import com.zouloux.core.navigation.MenuItem;
	import com.zouloux.ui.GenericButton;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	
	/**
	 * ...
	 * @author ZoulouX
	 */
	public class MenuItemButton extends GenericButton implements IExecutable
	{
		/**
		 * Le textField
		 */
		public var $nameTxt			:TextField;
		
		/**
		 * Le menuItem associé
		 */
		protected var _menuItem		:MenuItem;
		
		
		/**
		 * Le menuItem associé
		 */
		public function get menuItem():MenuItem { return _menuItem; }
		
		/**
		 * Le constructeur du bouton
		 * @param	pMenuItem : Le menu item associé
		 */
		public function MenuItemButton (pMenuItem:MenuItem, pAlign:String)
		{
			// Associer le menuItem
			_menuItem = pMenuItem;
			
			// Le texte
			if ($nameTxt != null)
			{
				$nameTxt.autoSize = pAlign;
				$nameTxt.text = _menuItem.name;
			}
			
			// Ecouter les clics
			addEventListener(MouseEvent.CLICK, clickHandler);
		}
		
		/**
		 * Clic sur ce bouton
		 * @param	event
		 */
		protected function clickHandler (event:MouseEvent):void 
		{
			execute();
		}
		
		/**
		 * Exécuter l'action
		 */
		public function execute ():void
		{
			_menuItem.execute();
		}
	}
}